import java.util.Arrays;

class TestHeap {

    public int[] elem;
    public int usedSize;

    public TestHeap() {
        this.elem = new int[10];//10个0
    }

    public void shiftDown(int parent) {
        int c=parent*2+1;
        while(c<this.usedSize){
            if(c+1<this.usedSize&&this.elem[c]<this.elem[c+1]){
                c++;
            }
            if(this.elem[c]<this.elem[parent]){
                int tmp=this.elem[c];
                this.elem[c]=this.elem[parent];
                this.elem[parent]=tmp;
                parent=c;
                c=parent*2+1;
            }else{
                break;
            }
        }
    }

    //1 4 18 7 .....
    public void createBigHeap(int[] array) {
        //把需要的数据 存放到elem当中 一会儿建堆的时候 直接操作 elem数组就可以了
        for (int i = 0; i < array.length; i++) {
            this.elem[i] = array[i];
            this.usedSize++;
        }

        for (int i = (this.usedSize-1-1)/2; i >= 0 ; i--) {
            shiftDown(i);
        }


    }

    public  boolean isFull() {
        return this.usedSize == this.elem.length;
    }

    public void push(int val) {
        if(isFull()) {
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize] = val;
        this.usedSize++;//
        //向上调整
        shiftUp(this.usedSize-1);
    }
    public void shiftUp(int child) {
        int parent = (child-1)/2;
        while (parent >= 0) {
            if(this.elem[parent]<this.elem[child]){
                int tmp=this.elem[parent];
                this.elem[parent]=this.elem[child];
                this.elem[child]=tmp;
                child=parent;
                parent=(child-1)/2;
            }else{
                break;
            }
        }
    }

}